<?php
declare (strict_types = 1);

namespace app\admin\validate\admin;

use think\Validate;

class BaseUser extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'username' => [
            'regex' => '/^[a-zA-Z0-9_-]{4,20}$/',

        ],
        'email' => [
            'regex' => '/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/',

        ],
        'mobile' => [
            'regex' => '/^1[3-9]\d{9}$/',

        ],
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [];

    protected $scene = [
        'add'  => ['username','email','mobile','password',],
        'update'  => ['username','email','mobile',],

    ];
    protected function checkPassword(string $value): bool
    {
        $decryptedPassword = \utils\crypt\Crypt::decrypt($value);
        if (preg_match("/^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,20}$/", $decryptedPassword)) {
            return true;
        }
        return false;
    }

}